package server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class demo1 {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入名字");
        String i1 = scanner.next();
        //加载驱动类
        Class.forName("com.mysql.cj.jdbc.Driver");
        //建立数据库的连接
        String url = "jdbc:mysql://localhost:3306/mybattis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8";
        String username= "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, username, password);

        Statement statement = connection.createStatement();
        //sql语句
        String sql = "insert into student(name ,tid) values('"+i1+"','1')";
        //执行
        int i = statement.executeUpdate(sql);
        //关联
        connection.close();
        statement.close();


    }

}
